From f9830fe742fa45baa87ae980ea68a3a3e2849a60 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 10 Jul 2014 18:26:30 -0700 Subject: [PATCH] Implement a `plugin` flag for targets If `plugin = true` is specified, then the target is considered a compiler plugin which implies two separate properties: * The library must be compiled as a dylib * The library must be compiled for the host architecture --- src/cargo/core/manifest.rs | 24 +++++++++++++++++++----- src/cargo/ops/cargo_rustc.rs | 4 ++-- src/cargo/util/toml.rs | 27 +++++++++++++++++++-------- 3 files changed, 40 insertions(+), 15 deletions(-) diff --git a/src/cargo/core/manifest.rs b/src/cargo/core/manifest.rs index 724f5216e..981547116 100644 --- a/src/cargo/core/manifest.rs +++ b/src/cargo/core/manifest.rs @@ -107,6 +107,7 @@ pub struct Profile { debug: bool, test: bool, dest: Option, + plugin: bool, } impl Profile { @@ -116,7 +117,8 @@ impl Profile { opt_level: 0, debug: true, test: false, // whether or not to pass --test - dest: None + dest: None, + plugin: false, } } @@ -126,7 +128,8 @@ impl Profile { opt_level: 0, debug: true, test: true, // whether or not to pass --test - dest: Some("test".to_string()) + dest: Some("test".to_string()), + plugin: false, } } @@ -136,7 +139,8 @@ impl Profile { opt_level: 3, debug: false, test: true, // whether or not to pass --test - dest: Some("bench".to_string()) + dest: Some("bench".to_string()), + plugin: false, } } @@ -146,7 +150,8 @@ impl Profile { opt_level: 3, debug: false, test: false, // whether or not to pass --test - dest: Some("release".to_string()) + dest: Some("release".to_string()), + plugin: false, } } @@ -158,6 +163,10 @@ impl Profile { self.test } + pub fn is_plugin(&self) -> bool { + self.plugin + } + pub fn get_opt_level(&self) -> uint { self.opt_level } @@ -188,6 +197,11 @@ impl Profile { self.test = test; self } + + pub fn plugin(mut self, plugin: bool) -> Profile { + self.plugin = plugin; + self + } } #[deriving(Clone, Hash, PartialEq)] @@ -196,7 +210,7 @@ pub struct Target { name: String, src_path: Path, profile: Profile, - metadata: Option + metadata: Option, } #[deriving(Encodable)] diff --git a/src/cargo/ops/cargo_rustc.rs b/src/cargo/ops/cargo_rustc.rs index 378efd902..6f5acc646 100644 --- a/src/cargo/ops/cargo_rustc.rs +++ b/src/cargo/ops/cargo_rustc.rs @@ -330,11 +330,11 @@ fn build_base_args(into: &mut Args, } match cx.config.target() { - Some(target) => { + Some(target) if !profile.is_plugin() => { into.push("--target".to_string()); into.push(target.to_string()); } - None => {} + _ => {} } } diff --git a/src/cargo/util/toml.rs b/src/cargo/util/toml.rs index 854609c2f..232cf0a0e 100644 --- a/src/cargo/util/toml.rs +++ b/src/cargo/util/toml.rs @@ -5,7 +5,7 @@ use std::io::fs; use toml; use core::{SourceId, GitKind}; -use core::manifest::{LibKind, Lib, Profile}; +use core::manifest::{LibKind, Lib, Dylib, Profile}; use core::{Summary, Manifest, Target, Dependency, PackageId}; use core::package_id::Metadata; use core::source::Location; @@ -201,7 +201,8 @@ fn inferred_lib_target(name: &str, layout: &Layout) -> Option> { name: name.to_string(), crate_type: None, path: Some(lib.display().to_string()), - test: None + test: None, + plugin: None, }] }) } @@ -219,7 +220,8 @@ fn inferred_bin_targets(name: &str, layout: &Layout) -> Option> name: name, crate_type: None, path: Some(bin.display().to_string()), - test: None + test: None, + plugin: None, } }) }).collect()) @@ -253,7 +255,8 @@ impl TomlManifest { name: t.name.clone(), crate_type: t.crate_type.clone(), path: layout.lib.as_ref().map(|p| p.display().to_string()), - test: t.test + test: t.test, + plugin: t.plugin, } } else { t.clone() @@ -272,7 +275,8 @@ impl TomlManifest { name: t.name.clone(), crate_type: t.crate_type.clone(), path: bin.as_ref().map(|p| p.display().to_string()), - test: t.test + test: t.test, + plugin: None, } } else { t.clone() @@ -376,7 +380,8 @@ struct TomlTarget { name: String, crate_type: Option>, path: Option, - test: Option + test: Option, + plugin: Option, } fn normalize(lib: Option<&[TomlLibTarget]>, @@ -390,7 +395,7 @@ fn normalize(lib: Option<&[TomlLibTarget]>, fn target_profiles(target: &TomlTarget, dep: Option) -> Vec { - let mut ret = vec!(Profile::default_dev(), Profile::default_release()); + let mut ret = vec![Profile::default_dev(), Profile::default_release()]; match target.test { Some(true) | None => ret.push(Profile::default_test()), @@ -402,6 +407,10 @@ fn normalize(lib: Option<&[TomlLibTarget]>, _ => {} } + if target.plugin == Some(true) { + ret = ret.move_iter().map(|p| p.plugin(true)).collect(); + } + ret } @@ -411,7 +420,9 @@ fn normalize(lib: Option<&[TomlLibTarget]>, let path = l.path.clone().unwrap_or_else(|| format!("src/{}.rs", l.name)); let crate_types = l.crate_type.clone().and_then(|kinds| { LibKind::from_strs(kinds).ok() - }).unwrap_or_else(|| vec!(Lib)); + }).unwrap_or_else(|| { + vec![if l.plugin == Some(true) {Dylib} else {Lib}] + }); for profile in target_profiles(l, Some(dep)).iter() { dst.push(Target::lib_target(l.name.as_slice(), crate_types.clone(), -- 2.30.2